package com.fire.shop.controller;


import com.fire.common.controller.BaseController;
import com.fire.common.core.page.TableDataInfo;
import com.fire.common.domain.Result;
import com.fire.shop.domain.Shop;

import com.fire.shop.service.ShopService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <h1>商铺管理控制类</h1>
 */
@RestController
@RequestMapping("/shop")
public class ShopController extends BaseController {

    // 注入ShopService
    @Autowired
    private ShopService shopService;



    /**
     * <h2>
     *     查询所有shop列表业务的url接口/shop/shop-list
     * </h2>
     * */

    @GetMapping("/shop-list")
    public TableDataInfo shopList(Shop shop) {
        startPage();
        List<Shop> list = shopService.queryAllShop(shop);
        return getDataTable(list);
    }
    /**
    * <h2>
     *     添加shop业务的url接口/shop/shop-add
    * </h2>
    * */
    @PostMapping("/shop-add")
    public Result addShop(@RequestBody Shop shop) {

        // 执行业务
        Result result = shopService.insert(shop);
        // 响应
        return result;
    }

    /**
     * <h2>
     *     修改shop信息业务的url接口/shop/shop-update
     * </h2>
     * */
    @RequestMapping("/shop-update")
    public Result updateShop(@RequestBody Shop shop){

        // 执行业务
        Result result = shopService.updateById(shop);
        // 响应
        return result;
    }

    /**
     * <h2>
     *     删除shop业务的url接口/shop/shop-delete/{shopId}
     * </h2>
     * */
    @RequestMapping("/shop-delete")
    public Result deleteShop(@RequestParam("id") String id) {

        // 执行业务
        Result result = shopService.deleteById(id);
        // 响应
        return result;
    }
}
